package com.cbgolf.oa.activity.parkdetails;

import android.os.Bundle;
import com.cbgolf.oa.R;
import com.cbgolf.oa.activity.BaseNewActivity;
import com.cbgolf.oa.contract.IPlayerCaddieCarDetailsContract.IPlayerCaddieCarDetailsPresenter;
import com.cbgolf.oa.contract.IPlayerCaddieCarDetailsContract.IPlayerCaddieCarDetailsView;
import com.cbgolf.oa.contract.IPlayerCaddieCarDetailsContract.IPlayerCaddieCarDetailsWaiter;
import com.cbgolf.oa.entity.LatLon;
import com.cbgolf.oa.entity.ParkFair;
import com.cbgolf.oa.event.EventPark;
import com.cbgolf.oa.manager.DataManager;
import com.cbgolf.oa.presenter.PlayerCaddieCarDetailsPresenterImp;
import com.cbgolf.oa.util.DataUtil;
import com.cbgolf.oa.util.TypeUtil;
import com.cbgolf.oa.util.Util;
import com.cbgolf.oa.views.PlayerCaddieCarDetailsViewImp;
import java.util.List;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * 打球人在场 ，打球人登记，球僮在场，球车在用----统计数据
 *
 * @author lq
 */
public class PlayerCaddieCarDetailsActivity extends BaseNewActivity implements
    IPlayerCaddieCarDetailsWaiter {

  /**
   * presenter
   */
  private IPlayerCaddieCarDetailsPresenter presenter;
  private IPlayerCaddieCarDetailsView view;
  /**
   * 对应不同的统计类别，展示不同数据
   */
  private int mType;
  private List<LatLon> listCaddie;
  private List<ParkFair> listCovertedAll;

  @Override
  protected int getLayoutId() {
    return R.layout.a_recycler_list;
  }

  @Override
  protected void init(Bundle savedInstanceState) {
    mType = DataUtil.getIntExtra(getIntent(), DataManager.KEY_TYPE, 0);
    EventBus.getDefault().register(this);
    view = new PlayerCaddieCarDetailsViewImp(this, this, mType);
    presenter = new PlayerCaddieCarDetailsPresenterImp(view);
    if (mType == DataManager.STATISTICS_PLAYER_IN_PARK) {
      Bundle b = getIntent().getExtras();
      if (null != b && b.containsKey(DataManager.KEY_DATA)) {
        listCaddie = (List<LatLon>) b.getSerializable(DataManager.KEY_DATA);
        listCovertedAll = (List<ParkFair>) b.getSerializable(DataManager.KEY_ALL);
      }
      if (!Util.listIsNull(listCaddie) && !Util.listIsNull(listCovertedAll)) {
        presenter.filterPlayerData(listCaddie, listCovertedAll);
      } else {
        view.showPlayers(null);
      }
    } else {
      presenter.requestData(mType, DataUtil.INITDATA, System.currentTimeMillis());
    }

  }

  @Override
  protected void onDestroy() {
    super.onDestroy();
    EventBus.getDefault().unregister(this);
  }

  @Subscribe(threadMode = ThreadMode.MAIN)
  public void requestOver(EventPark event) {
    if (null != view) {
      view.requestOver(event);
    }
  }

  @Override
  public String getActivityTitle() {
    String title;
    switch (mType) {
      case DataManager.STATISTICS_PLAYER_IN_PARK:
        title = DataManager.TITLE_STATISTICS_PLAYER_IN_PARK;
        break;
      case DataManager.STATISTICS_CADDIE_IN_PARK:
        title = DataManager.TITLE_STATISTICS_CADDIE_IN_PARK;
        break;
      case DataManager.STATISTICS_PLAYER_REG_DETAILS:
        title = DataManager.TITLE_STATISTICS_PLAYER_REG_DETAILS;
        break;
      case DataManager.STATISTICS_CAR_USING:
        title = DataManager.TITLE_STATISTICS_CAR_USING;
        break;
      default:
        title = DataManager.TITLE_STATISTICS_DEFAULT;
        break;
    }
    return title;
  }

  @Override
  public void back() {
    finish();
  }


  @Override
  public void requestTeetimeData(String teetimeDate) {
    presenter.requestData(mType, DataUtil.INITDATA, TypeUtil.parseLong(teetimeDate));

  }
}
